
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>下面程序的运行结果是? - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>下面程序的运行结果是? - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">代码分析</div>
          <div class="card-question">在给定的Java代码片段中，为什么循环结束后 `Set<Short>` 的大小是5，而不是预期的1？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">代码分析</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">最终大小为5是因为 `set.remove(i - 1)` 操作没有成功删除任何元素。虽然循环添加了5个元素，但删除操作因类型不匹配而失败。</div>
          </div>
          <div class="card-source">来源: 文档中第一个代码块下方的解释</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">语言特性</div>
          <div class="card-question">为什么在 `Set<Short>` 上调用 `remove(i - 1)` 会失败，其中 `i` 是 `short` 类型？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">语言特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">因为在Java中，当一个 `short` 类型的变量 `i` 和一个 `int` 类型的字面量 `1` 进行算术运算时，结果会自动提升为 `int` 类型。因此，`remove` 方法接收的是一个 `Integer` 对象，而Set中存储的是 `Short` 对象，导致无法找到并删除元素。</div>
          </div>
          <div class="card-source">来源: 文档中第一个代码块下方的解释</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">解决方案</div>
          <div class="card-question">如何修改代码，以确保在 `Set<Short>` 中能成功删除值为 `i - 1` 的元素？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">解决方案</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">需要将算术运算 `i - 1` 的结果显式地强制类型转换为 `short`，然后再调用 `remove` 方法。例如：`short x = (short) (i - 1); set.remove(x);`。</div>
          </div>
          <div class="card-source">来源: 文档中第二个代码块及其注释</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
